import { _decorator, animation, Animation } from "cc";
import { CocosUtils } from "../../utils/CocosUtils";
import { Spikes } from "../Spikes";
const { ccclass } = _decorator;

const NumWords = [
    "zero", "one", "two", "three", "four", "five"
];

@ccclass("SpikesIdleState")
export class SpikesIdleState extends animation.StateMachineComponent {

    public async onMotionStateEnter(controller: animation.AnimationController, motionStateStatus: Readonly<animation.MotionStateStatus>): Promise<void> {
        const spikes = controller.getComponent(Spikes);
        const animation = controller.getComponentInChildren(Animation);
        const totalCount = spikes.totalCount;
        const count = spikes.count;
        const animName = `spikes${NumWords[totalCount]}/${NumWords[count]}`;
        const atlasPath = `texture/spikes/spikes${NumWords[totalCount]}/${NumWords[count]}/${NumWords[count]}`;
        await CocosUtils.playAnimation(animation, animName, atlasPath);
        spikes.onTickComplete();
    }
}